import React from 'react';

import Constants from '../../common/Constants';
import CommonSendFetchAction from '../common/CommonSendFetchAction';

export default class PostRequestCommentListAction extends CommonSendFetchAction {
  constructor() {
    super();

    this.moduleType = Constants.MODULE_TYPE.POST;
    this.name = "PostRequestCommentListAction";
  }

  _dealCall(caller, data) {
    caller.setState({
      commentLoading:true,
    })
  }
  isArray(o){
    return Object.prototype.toString.call(o)=='[object Array]';
  }
  _dealFinishSucess(data, response) {
    var arr = [];
    if (this.isArray(data)) {
      arr = data;
    }
    if (data.comments) {
      arr = data.comments;
    }
    this.caller.setState({
      commentData:arr,
      commentLoading:false,
      commentLoadComplete:true,
      statusText:"",
    })
  }

  _dealFinishFailed(data, response) {
    let detail = "服务器错误";
    if(data && data.detail != undefined) {
      detail = data.detail;
    }
    detail = detail + " " + response.status;
    this.caller.setState({
      commentLoading:false,
      commentLoadComplete:true,
      statusText:detail,
      commentData:[],
    })
  }
}
